package com.ssss.iter;

import java.util.ArrayList;
import java.util.NoSuchElementException;

public class ConcreateIteator<E> implements Iterator<E>{

    private int cursor; // 游标
    private ArrayList arrayList;

    public ConcreateIteator(int cursor, ArrayList arrayList) {
        this.cursor = 0;
        this.arrayList = arrayList;
    }

    @Override
    public boolean hasNext() {
        if (this.cursor == this.arrayList.size()){
            return false;
        }
        return true;
    }

    @Override
    public void next() {
        cursor++;
        System.out.println(cursor + "cursor");
    }

    @Override
    public E currentItem() {
       if (cursor >= arrayList.size()){
           throw new NoSuchElementException();
       }
       E e  = (E) arrayList.get(cursor);
       this.next();
       return e;
    }
}
